package nconv.convert.plugins;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static nconv.convert.TGPP2WikiConverter.LooseAVPPatternStr;

/**
 * Created by xiaobyu on 2017/1/24.
 */
public class P29219 extends DefaultTGPPConvertPlugin{
  private final static Pattern AVPInTablePattern = Pattern.compile("\\|-\n\\|(\\s*colspan=\"\\d\"\\s*\\|)?"
          + "(<span id='\\w+'>)?" //G2
          + LooseAVPPatternStr //G3-G4
          + "(</span>)?" //G5
          + "\\s*" //fixed the issue that there could be spaces after AVP name
          + "(\\s+[^\\|\n]+)?\n+" + //G6
          "\\|(\\d+|TBD)[^\\|]*\\n+" + //code G7
          "\\|[^\n]+\\n+" + //clause
          "\\|([^\n]+)\\n+" + //type G8
          "\\|([^\\|]*)\\n+" + //must G9
          "\\|([^\\|]*)\\n+" + //may  G10
          "\\|([^\\|]*)\\n+" + //should not G11
          "\\|([^\\|]*)\\n+" //must not G12
  );

  public String reviseAVPTable(String tableName, String content) {
    /*
    if (tableName != null && tableName.contains("Sy specific Diameter")) {
      Matcher m = AVPInTablePattern.matcher(content);
      StringBuffer sb = new StringBuffer();
      int lastIdx = 0;
      while (m.find()) {
        int i12e = m.end(12);
        sb.append(content.substring(lastIdx, i12e))
                .append("\n|Y\n");
        lastIdx = i12e;
      }
      sb.append(content.substring(lastIdx));
      return sb.toString();
    }
    */
    return content.replace("Pending-Policy-Counter<span id='OLE_LINK6'><span id='OLE_LINK5'>-Information</span></span>",
            "<span id='OLE_LINK6'><span id='OLE_LINK5'>Pending-Policy-Counter-Information</span></span>");
  }
}
